<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
<script type="text/javascript" src="../../res/js/jquery-3.1.1.min.js"></script>
<script src="../../res/layui/layui.js"></script>
<script src="../../res/js/Tools.js"></script>
<body>
<form class="layui-form" action="" lay-filter="example" id="example">
    <input type="hidden" name="schemeId" id="schemeId">
    <input type="hidden" name="athleteId" id="athleteId">
    <div class="layui-form-item">
        <label class="layui-form-label">实施情况</label>
        <div class="layui-input-block">
            <input type="text" name="resultExp" id="resultExp" lay-verify="required" placeholder="请输入实施情况"  class="layui-input">
        </div>
    </div>


    <div class="layui-form-item" ID="SDSD">
        <label class="layui-form-label">实施附件</label>
        <button type="button" class="layui-btn layui-btn-normal" lay-verify="file" id="test8">选择文件</button>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">实施效果</label>
        <div class="layui-input-block">
            <input type="text" name="resultEffect" id="resultEffect" lay-verify="required" autocomplete="off"   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo">立即提交</button>
        </div>
    </div>
</form>
</body>
<script>
    layui.use(['form','upload'],function(){
        var upload = layui.upload;
        var form = layui.form;
        var schemeId = getQueryString("schemeId");


        $("#schemeId").val(schemeId);
        $("#SDSD  input").val();
        form.on('submit(demo)',function(obj){
            var r = $("#SDSD  input").val();

            var formdata = new FormData(document.getElementById("example"));
            var url = "../../atsScheme/insertResult";

            if(r != null ){

                $.ajax({
                    url:url,
                    type:"post",
                    data:formdata,
                    async:false, // 全局同步
                    processData:false,
                    contentType:false,
                    dataType:"json",
                    success:function(obj){

                        if(obj.num==1){
                            layer.msg('增加成功',{
                                icon:1,
                                time:1000,
                            },function(){
                                var indexs = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(indexs);
                                parent.table2.reload();
                            });
                        }else{
                            layer.msg("增加失败");
                        }
                    },
                    error:function(e){
                        alert("失败");
                    }
                });
            }else{
                layer.msg("附件1不能为空");

            }
            return false ;
        });
        //选完文件后不自动上传
        upload.render({
            elem: '#test8'
            ,url: '/upload/'
            ,auto: false
            //,multiple: true
            ,accept: 'file' //普通文件
            ,bindAction: '#demo'
            ,done: function(res){
                console.log(res)
            }
        });


    });
</script>
</html>